##
## This file is part of the django-oidauth project.
##
## Copyright (C) 2009 Filippo Santovito <http://mementomori.myvidoop.com/>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License version 3 as
## published by the Free Software Foundation;
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
##

from django import template
from oidauth.models import OpenID

register = template.Library()

def fields(user):
    "value is a user object"
    fields = []
    try:
        for field in  user.get_profile()._meta._fields():
            if field.name not in ['id','user']:
                fields.append([field.name, field.value_to_string(user.get_profile())])

    except OpenID.DoesNotExist, e:

        for field in  user._meta._fields():
            if field.name not in ['id', 'password']:
                fields.append([field.name, field.value_to_string(user)])
    
    return fields

register.filter('fields', fields)
